#include<iostream>
#include<cstring>
using namespace std;
class CCount
{
    protected:
        int value;
    public:
        CCount(int _va=0):value(_va){ }
        int increment(int s)
        {
            value+=s;
            return 0;
        }
};
class CCal:public CCount
{
    private:
        int minValue,maxValue;
    public:
        CCal(int _va,int _minV,int _maxV):CCount(_va)
        {
            minValue=_minV;
            maxValue=_maxV;
        }
        int increment(int s)
        {
            value+=s;
            int tmp=value/(maxValue+1);
            value=value-tmp*(maxValue+1);
            if(value>maxValue)
                value=minValue;
            return tmp;
        }
        int getValue()
        {
            return value;
        }
};
class CClock
{
    private:
        CCal hour,minute,second;
    public:
        CClock(int hva,int mva,int sva,int _hminV=0,int _hmaxV=23,int mminV=0,int mmaxV=59,int sminV=0,int smaxV=59):hour(hva,_hminV,_hmaxV),minute(mva,mminV,mmaxV),second(sva,sminV,smaxV){ }
        void TTime(int s)
        {
            int tmp=second.increment(s);
            if(tmp>0)
            {
                int tmp2=minute.increment(tmp);
                if(tmp2>0)
                {
                    int tmp3=hour.increment(tmp2);
                }
            }
        }
        void disPlay()
        {
            cout<<hour.getValue()<<":"<<minute.getValue()<<":"<<second.getValue()<<endl;
        }
};
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c;
        int s;
        cin>>a>>b>>c;
        cin>>s;
        CClock tmp(a,b,c);
        tmp.TTime(s);
        tmp.disPlay();
    }
}